<template>
    <el-form ref="sellersRules" :model="sellers" :rules="rules" label-width="80px" class="demo-ruleForm" style="width: 600px">
        <el-form-item label="商家名称" prop="sname">
            <el-input v-model="sellers.sname"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit('sellersRules')">立即创建</el-button>
            <el-button @click="subSellers()">取消</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
    export default {
        name: "sellerssadd",
        data() {
            return {
                sellers: {
                    sid: '',
                    sname: ''
                },
                rules:{
                    sname:[
                        { required: true, message: '请输入商家名称', trigger: 'blur' }
                    ]
                }
            }
        },
        methods: {
            onSubmit(formName){
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        let _this = this
                        axios.post('http://localhost:8888/chuyangc/sellers/add',this.sellers).then(function (response) {
                            if(response.data){
                                _this.$alert(_this.sellers.sname+'添加成功！', '添加数据', {
                                    confirmButtonText: '确定',
                                    callback: action => {
                                        //跳转到/table
                                        _this.$router.push('/sellers')
                                    }
                                });
                            }
                        })
                    }
                });
            },
            subSellers(){
                this.$router.push('/sellers')
            }
        }
    }
</script>

<style scoped>

</style>